package com.joyoung.sweep.utils;

import android.Manifest;
import android.content.Context;

import com.blankj.utilcode.util.ToastUtils;
import com.tbruyelle.rxpermissions.RxPermissions;


/**
 * @author: ThinkPad
 * date: 2021/4/22
 * desc: 权限
 */
public abstract class PermissionUtils {
    private Context mContext;
    public static String[] ALL = {
            Manifest.permission.CAMERA,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
    };

    public PermissionUtils(Context ctx, String[] permission) {
        this.mContext = ctx;
        requestPermission(permission);
    }

    private void requestPermission(String[] permission) {
        RxPermissions.getInstance(mContext)
                .request(permission)
                .subscribe(granted -> {
                    if (granted) {
                        onSuccess();
                    } else {
                        ToastUtils.showShort("权限被拒，影响手机功能正常使用");
                    }
                });
    }

    /**
     * 成功
     */
    public abstract void onSuccess();
}
